package vip.meeet.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import vip.meeet.bean.Result;
import vip.meeet.bean.echarts.AxisType;
import vip.meeet.bean.echarts.ChartType;
import vip.meeet.bean.echarts.EData;
import vip.meeet.helper.EchartsHelper;
import vip.meeet.helper.ResultHelper;

import java.util.Arrays;

@Controller
@RequestMapping("/bar")
public class BarController {


    @RequestMapping("/one/1")
    @ResponseBody
    public Result one1(){
        Integer[] amounts = {5200,93600,520000,1910000,3500000,5710000,9120000,12070000,16820000,21350000,26840000,49820000};//万
        Integer[] year = {2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020};

        EData data = EchartsHelper.buildSerie(ChartType.BAR, "TM", Arrays.asList(amounts));
        EData x = EchartsHelper.buildX(AxisType.CATEGORY, Arrays.asList(year));
        EData y = EchartsHelper.buildY(AxisType.VALUE, "单位:万");
        JSONObject result = EchartsHelper.buildLineResult(
                "天猫销售额",
                Arrays.asList("销售额"),
                x,
                y,
                data
        );
        return ResultHelper.getSuccessResult(result);
    }

    @RequestMapping("/two/1")
    @ResponseBody
    public Result two1(){
        Integer[] tm = {1682,2135,2684,4982};//亿
        Integer[] jd = {1271,1598,2044,2715};//亿
        Integer[] year = {2017,2018,2019,2020};

        EData tmData = EchartsHelper.buildSerie(ChartType.BAR, "天猫", Arrays.asList(tm));
        EData jdData = EchartsHelper.buildSerie(ChartType.BAR, "京东", Arrays.asList(jd));
        EData x = EchartsHelper.buildX(AxisType.CATEGORY, Arrays.asList(year));
        EData y = EchartsHelper.buildY(AxisType.VALUE, "单位:亿");
        JSONObject result = EchartsHelper.buildLineResult(
                "天猫京东销售额对比",
                Arrays.asList("天猫","京东"),
                x,
                y,
                Arrays.asList(tmData,jdData)
        );
        return ResultHelper.getSuccessResult(result);
    }

}
